package com.sunshine.monitor.jvm;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;

public class JVMThread implements IJVMThread {
	private static final JVMThread jvmThread = new JVMThread();

	private ThreadMXBean threadMXBean;

	
	
	public static IJVMThread getInstace(){
		return jvmThread;
	}
	private JVMThread() {
		threadMXBean = ManagementFactory.getThreadMXBean();
	
	}

	public long getThreadTotalCount() {
		return threadMXBean.getThreadCount();
	}

	public long getStartedThreadCount() {
		return threadMXBean.getTotalStartedThreadCount();
	}

	public long getDealLockThreadCount() {
		long [] ids = threadMXBean.findDeadlockedThreads();
		if(null!=ids){
			return ids.length;
		}
		return 0;
	}

	public long getPeakThreadCount() {
		return threadMXBean.getPeakThreadCount();
	}

	public long getDeamonThreadCount() {
		return threadMXBean.getDaemonThreadCount();
	}

	
	
}
